let v = new Vue({
    el:'#main-container',
    data:{
        article:{

        },
        ifFavorite:false,
        favPeople:[],

    },
    methods:{
        initPage:function () {
            axios({
                url:'main/article/findfavouriteNum',
                data:this.article,
                method:'post',
            }).then(resp => {
                this.article.favoriteNum = resp.data.obj;
            }).catch(error => {
                layer.msg(error.message);
            })
        },
        browseIncr:function () {
            axios({
                url:'main/article/browseIncr',
                method:'post',
                data:this.article,
            }).then(resp => {
                if(resp.data.success){
                    this.article.browseCount = this.article.browseCount + 1;
                }else{
                    layer.msg("初始化失败");
                }
            }).catch(error => {
                layer.msg(error.message);
            })
        },
        whoFavorite:function () {
            axios({
                url:`main/article/whoFavorite/${this.article.id}`,
            }).then(resp => {
                if(resp.data.success){
                    this.ifFavorite = resp.data.obj.ifFavorite;
                    this.favPeople = resp.data.obj.favPeople;
                }else{
                    layer.msg("初始化失败");
                }
            }).catch(error => {
                layer.msg(error.message);
            })
        },
        toDetail:function (thisUser) {
            layer.obj = thisUser;
            if(thisUser.isSecret == 0){
                layer.msg("该用户设置了私密信息，不可查看");
            }else{
                layer.open({
                    type: 2,
                    title: '详细信息',
                    area: ['100%', '100%'],
                    content: 'main/user/toDetail',
                    end:() => {

                    }
                })
            }
        },
        changeFav:function () {
            axios({
                url:`main/article/changeFav/${this.article.id}`,
            }).then(resp => {
                if(resp.data.success){
                    this.ifFavorite = !this.ifFavorite;
                    if(this.ifFavorite){
                        layer.msg("收藏成功");
                        this.article.favoriteNum = this.article.favoriteNum + 1;
                    }else {
                        layer.msg("取消成功");
                        this.article.favoriteNum = this.article.favoriteNum - 1;
                    }
                }else{
                    layer.msg("操作失败");
                    this.whoFavorite();
                }
            }).catch(error => {
                layer.msg(error.message);
            })
        }
    },
    created:function () {
        this.article = parent.layer.article;
        this.initPage();
        this.browseIncr();
        this.whoFavorite();
    }
})